import pathway as pw
from application.db.mysql_db.nsfc.NsfcPublishProjectCodeDict import NsfcPublishProjectCodeDict


class NsfcPublishProjectCodeDictSchema(pw.Schema):
    apply_code: str
    code_name: str
    parent_code: str=pw.column_definition(default_value="")


class NsfcPublishProjectCodeDictRead(pw.io.python.ConnectorSubject):
    
    def run(self):
        select_list = NsfcPublishProjectCodeDict.select().dicts()
        for doc in select_list:
            doc = self.transform(doc)
            self.next(**doc)
    
    def transform(self, transform_data):
        transform_data = {k: v for k, v in transform_data.items()
                          if v is not None and v != {}}
        
        return transform_data